package com.herench.bunch.clinic.support;


import org.apache.log4j.Logger;
import com.herench.bunch.commons.support.MessageHandler;
import com.herench.bunch.commons.support.ServicePool;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.core.type.classreading.CachingMetadataReaderFactory;
import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.stereotype.Component;
import org.springframework.util.ClassUtils;

import javax.annotation.PostConstruct;
import java.util.HashSet;
import java.util.Set;

/**
 * Created by ThinkPad on 2017/8/24.
 */

@Component
public class CleverClinicContext {


    private static final Logger logger = Logger.getLogger(CleverClinicContext.class);

    @Autowired
    private ApplicationContext applicationContext;

    private Set<String> greenChannelCodes;



    private boolean alive;

    private ServicePool<String, MessageHandler> messageHandlerServicePool;


    private ResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver();
    private String basePackage = "com.herench.bunch.clinic.handler";
    static final String DEFAULT_RESOURCE_PATTERN = "**/*.class";
    private String resourcePattern = DEFAULT_RESOURCE_PATTERN;
    private MetadataReaderFactory metadataReaderFactory;




    public boolean isAlive() {
        return alive;
    }

    public CleverClinicContext() {
    }





    public ServicePool<String, MessageHandler> getMessageHandlerServicePool() {
        return messageHandlerServicePool;
    }


    public ApplicationContext getApplicationContext() {
        return applicationContext;
    }

    public void setApplicationContext(ApplicationContext applicationContext) {
        this.applicationContext = applicationContext;
    }

    public Set<String> getGreenChannelCodes() {
        return greenChannelCodes;
    }




    private String resolveBasePackage(String basePackage) {
        return ClassUtils.convertClassNameToResourcePath(basePackage);
    }
}
